
<template>
  <!-- 榜单页面 -->
  <div>
    <div class="pylst" v-if="playlist">
      <div class="pylst_header">
        <div class="pylst_bg">
          <div class="bg_img">
            <img :src="playlist.coverImgUrl" />
          </div>
        </div>
        <div class="plhead_fr" @click.prevent="$router.go(-1)">
          <span class="iconfont icon-fanhui1">
            {{ playlist.tags[0] || "歌曲" }}</span
          >
        </div>
        <div class="pylst_name">{{ playlist.name || "榜单" }}</div>
        <div class="right-likesong" @click="likesong(playlist.id)">
          <span v-if="state==true" class="red iconfont icon-shoucang"></span>
          <span v-else class="iconfont icon-shoucang"></span>
        </div>
      </div>
    </div>
    <div class="pylst_main">
      <div class="plylist_top border-bottom" v-if="playlist">
        <span class="play_icon"></span>
        <span>播放全部（共{{ playlist.tracks.length }}首）</span>
      </div>
      <div class="pylst_list" v-if="playlist">
        <ul>
          <li
            class="border-bottom"
            v-for="(item, index) in playlist.tracks"
            :key="item.id"
            @click="setId(item.id)"
          >
            <div class="num">{{ index + 1 }}</div>
            <div class="pylst_mess">
              <p>{{ item.name }}</p>
              <p>
                <span v-for="value in item.ar" :key="value.id">{{
                  value.name
                }}</span>
              </p>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import { getPlaylistDetail, getLikesubScribe } from "../../api/rank";
export default {
  data() {
    return {
      playlist: null,
      state:""
    };
  },
  created() {
    // console.log(this)
    let queryId = this.$route.query;
    // console.log(queryId)
    // console.log( this.$route)
    if (!("id" in queryId)) {
      this.$router.push("/rank");
    }
    // getPlaylistDetail
    getPlaylistDetail({ id: queryId.id }).then((data) => {
      console.log(data);
      this.playlist = data.playlist;
      this.state =  this.playlist.subscribed
      console.log(this.state)
    });
  },
  methods: {
    setId(id) {
      console.log(id)
      this.$emit("get-play-all-id", this.$route.query.id); //传递当前歌曲id
      //将当前歌曲id，传递给APP.vue
      this.$emit("get-player-id", id);
    },


    likesong(id) {
      let t;
      console.log(id);
      // getLikesubScribe
      if (this.state==true) {
        t = 2;
        getLikesubScribe({ id: this.playlist.id, t: t });
        Toast("取消收藏");
        this.state = false
        // console.log(t,this.state)
      } else {
        t = 1;
        getLikesubScribe({ id: this.playlist.id, t: t });
        Toast("收藏成功");
         this.state = true
          // console.log(t,this.state)
      }
    },
  },
};
</script>

<style lang="less">
.play_icon {
  display: inline-block;
  flex: 0 0 18px;
  height: 18px;
  position: relative;
  border-radius: 100%;
  border: 2px solid #acadad;
}
.play_icon::after {
  content: "";
  position: absolute;
  display: block;
  border-style: solid;
  border-width: 6px 7.2px 6px 7.2px;
  border-color: transparent transparent transparent #212322;
  width: 0px;
  height: 0px;
  left: 40%;
  top: 40%;
  transform: translate(-2%, -30%);
}
.pylst_header {
  height: 269px;
  position: relative;
  font-size: 16px;
  color: #fff;
  z-index: 1;
  .pylst_bg {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
    .bg_img {
      padding-bottom: 100%;
      position: relative;
      img {
        width: 100%;
        position: absolute;
        top: -14%;
      }
    }
  }
  .plhead_fr {
    padding-left: 18px;
    height: 48px;
    line-height: 48px;
  }
  .pylst_name {
    position: absolute;
    left: 22px;
    bottom: 16px;
  }

  .right-likesong {
    position: absolute;
    right: 22px;
    bottom: 16px;
    .iconfont {
      font-size: 20px;
    }
    .red {
      color: red;
    }
  }
}

.pylst_main {
  position: relative;
  z-index: 2;
  background-color: #fff;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  margin-top: -7px;
  padding-bottom: 50px;
  .border-bottom {
    border-bottom: 1px solid #e7e7e7;
    padding-left: 18px;
    box-sizing: border-box;
  }
  .plylist_top {
    display: flex;
    align-items: center;
    height: 36px;
    line-height: 36px;
    span {
      margin-right: 16px;
    }
  }
  .pylst_list {
    ul li {
      display: flex;
      padding: 10px 0 10px 18px;
      .num {
        width: 5%;
        text-align: center;
        line-height: 38px;
        margin-right: 16px;
        color: #999;
      }
      .pylst_mess {
        flex: 1 1 auto;
        p {
          width: 80%;
          font-size: 17px;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
          overflow: hidden;
        }
        p:nth-of-type(2) {
          font-size: 12px;
          color: #888;
        }
      }
    }
  }
}
</style>